package com.smart.sso.server.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.smart.sso.server.dao.UserDao;
import com.smart.sso.server.model.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.smart.sso.client.rpc.Result;
import com.smart.sso.client.rpc.SsoUser;
import com.smart.sso.server.service.UserService;

import javax.annotation.Resource;

@Service("userService")
public class UserServiceImpl implements UserService {

	@Resource
	private UserDao userDao;

//	@Autowired
//	private RocketMQTemplate rocketMQTemplate;
	
	@Override
	public Result<SsoUser> login(String username, String password) {
		QueryWrapper<UserEntity> wrapper = new QueryWrapper<>();
		wrapper.eq("nick_name",username);
		UserEntity user = userDao.selectOne(wrapper);
		if(null != user){
			if(user.getPassword().equals(password)){
//				rocketMQTemplate.convertAndSend("FinancialProject", JSON.toJSONString(user));
				return Result.createSuccess(new SsoUser(user.getUserId(), user.getNickName()));
			}else {
				return Result.createError("密码有误");
			}
		}
		return Result.createError("用户不存在");
	}
}
